<template>
	<view>
		<u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules" ref="inputForm">
			<u-form-item label="类型" borderBottom prop="name">
			    <jp-picker v-model="inputForm.leaveType" rangeKey="label" rangeValue="value" :range="$dictUtils.getDictList('oa_leave_type')"></jp-picker>
			</u-form-item>

			<u-form-item label="请假开始时间" borderBottom prop="startTime">
			    <jp-datetime-picker  v-model="inputForm.startTime"  mode="datetime"></jp-datetime-picker>
			</u-form-item>
			
			<u-form-item label="请假结束时间" borderBottom prop="endTime">
			    <jp-datetime-picker  v-model="inputForm.endTime"  mode="datetime"></jp-datetime-picker>
			</u-form-item>
			
			<u-form-item label="请假事由" borderBottom prop="reason">
			    <u--textarea  placeholder='请填写请假事由'  v-model="inputForm.reason" ></u--textarea>
			</u-form-item>
			
		</u--form>
	</view>
</template>

<script>
	import jpPicker from '@/pages/subA/components/jp-picker/jp-picker.vue';
	import testActivitiLeaveService from "@/api/test/activiti/testActivitiLeaveService"
	export default {
		components: {
			jpPicker
		},
		data () {
			return {
				loading: false,
				inputForm: {
				  id: '',
				  leaveType: '',
				  startTime: '',
				  endTime: '',
				  reason: ''
				},
				rules: {
					  'leaveType': [
					  {
							required: true,
							message: '类型不能为空',
							trigger: ['blur', 'change']
					  }],
					  'startTime': [
					  {
							required: true,
							message: '请假开始时间不能为空',
							trigger: ['blur', 'change']
					  }],
					  'endTime': [
					  {
							required: true,
							message: '请假结束时间不能为空',
							trigger: ['blur', 'change']
					  }],
					  'reason': [
					  {
							required: true,
							message: '请假事由不能为',
							trigger: ['blur', 'change']
					  }]
				}
			}
		},
		props: {
		  businessId: {
		    type: String,
		    default: ''
		  },
		  formReadOnly: {
		    type: Boolean,
		    default: false
		  }
		},
		watch: {
		  'businessId': {
		    handler (newVal) {
		      if (this.businessId) {
		        this.init(this.businessId)
		      } else {
		        this.$nextTick(() => {
		          // this.$refs.inputForm.reset()
		        })
		      }
		    },
		    immediate: true,
		    deep: false
		  }
		},
		methods: {
			init (id) {
			  if (id) {
				  testActivitiLeaveService.queryById(id).then((data) => {
			        this.inputForm = this.recover(this.inputForm, data)
			      })
			  }
			},
			saveForm (callback) {
					//定义表单规则
				this.$refs.inputForm.validate().then(res => {
					uni.showLoading()
					testActivitiLeaveService.save(this.inputForm).then((data) => {
						  callback(data.businessTable, data.businessId)
					}).catch((e)=>{
						
					})
				}).catch((e)=>{
					
				})	
			}
		}
	  }
</script>

<style>
	.cu-form-group .title {
		min-width: calc(4em + 40px);
	}


</style>
